package net.dgg.zz.api.production.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserDTO;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import net.dgg.tmd.foundation.platform.user.service.UserService;
import net.dgg.zz.api.production.service.ApiProductionService;
import net.dgg.zz.common.constant.ScProductConstant;
import net.dgg.zz.common.service.CommonMangerExtService;
import net.dgg.zz.common.service.CommonService;
import net.fblock.log.NLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>@Title 生产部分对外接口controller</p>
 * <p>@Description 办理中相关</p>
 * <p>@Version 1.0.0 版本号</p>
 * <p>@author maoquanyi</p>
 * <p>@date 2018年08月13日</p>
 * <p>Copyright © dgg group.All Rights Reserved. 版权信息</p>
 */
@Controller
@RequestMapping("/zzsc/production")
@Api(description = "生产工作台接口")
public class ApiProductionController extends DggBaseController {

    @Resource
    private ApiProductionService apiProductionService;
    @Autowired
    private CommonMangerExtService commonMangerExtService;
    @Resource
    private UserService userService;
    @Resource
    private CommonService commonService;
    @Autowired
    private SessionManager sessionManager;
    //---------------  分单人员 工作台 9个 开始 -----------------------
    /**
     * <p>@Description 分单人员 分配总量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_allot_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员分配总量", notes = "分单人员当月的分配总量", httpMethod = "POST")
    public DggRestResponse allAllotCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //操作人ID
            params.put("operaterId",userId);
            //操作类型: 分配 17
            params.put("operateTypeList",new String[]{"17"});
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productSystemCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 分单人员 待接收数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_receive_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员待接收", notes = "分单人员本月分配出去的待接收的数量", httpMethod = "POST")
    public DggRestResponse waitReceiveCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //分配人是自己的
            params.put("allotUserId",userId);
            //各种待接收
            params.put("statusList",new String[]{ScProductConstant.SC_TO_RECEIVE_FPDJS
                    ,ScProductConstant.SC_TO_RECEIVE_ZDDJS,ScProductConstant.SC_TO_RECEIVE_YJDJS,ScProductConstant.SC_TO_RECEIVE_TDDJS});
            params.put("allotDateCurrentMonth","yes");//分配时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 分单人员 办理量统计(统计当月进入办理中的数量) </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/handle_inprocess_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员办理量", notes = "分单人员本月分配出去的还在办理中的数量", httpMethod = "POST")
    public DggRestResponse handleInprocessCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //分配人是自己的
            params.put("allotUserId",userId);
            //不用管现在是否办理中,当月分配就行
            params.put("allotDateCurrentMonth","yes");//分配时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 分单人员 生产完结量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_over_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员生产完结量", notes = "分单人员分配出去的本月完结的数量", httpMethod = "POST")
    public DggRestResponse allOverCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //分配人是自己的
            params.put("allotUserId",userId);
            //完结
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE});
            params.put("allotDateCurrentMonth","yes");//分配时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 分单人员 已退订单量 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/complete_back_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员已退订单量", notes = "分单人员分配出去的本月退单完成的数量", httpMethod = "POST")
    public DggRestResponse completeBackCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //分配人是自己的
            params.put("allotUserId",userId);
            //已退单
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK});
            params.put("returnMonth","yes");//退单完成时间为当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 分单人员 结项订单量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_junctions_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员结项订单量", notes = "分单人员分配出去的本月结项的数量", httpMethod = "POST")
    public DggRestResponse allJunctionsCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //分配人是自己的
            params.put("allotUserId",userId);
            //结项
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_JUNCTIONS});
            params.put("allotDateCurrentMonth","yes");//分配时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 分单人员 所有的 待分配数量 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_allot_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员待分配数量", notes = "所有待分配的数量", httpMethod = "POST")
    public DggRestResponse waitAllotCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //查本事业部的
            Long userSybId = commonService.findUserSyb(userEntity);//查事业部ID
            params.put("signOrgId",userSybId);
            //待分配和退回待分配
            params.put("statusList",new String[]{ScProductConstant.SC_TO_RECEIVE_XDDJS,ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 分单人员 分配退回数量 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_allot_back_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员分配退回", notes = "所有退回待分配的数量", httpMethod = "POST")
    public DggRestResponse waitAllotBackCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //查本事业部的
            Long userSybId = commonService.findUserSyb(userEntity);//查事业部ID
            params.put("signOrgId",userSybId);
            //退回待分配
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 分单人员 分配超期</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 14:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/allot_over_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "分单人员分配超期", notes = "所有分配超期的数量", httpMethod = "POST")
    public DggRestResponse allotOverCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //查本事业部的
            Long userSybId = commonService.findUserSyb(userEntity);//查事业部ID
            params.put("signOrgId",userSybId);
            //分配超期状态为超期
            params.put("distributionTimeOutStatus",ScProductConstant.TIME_OUT);
            params.put("notAllotStatus","yes");
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    //---------------  分单人员 工作台 结束 -----------------------

    //---------------  生产人员 工作台 12个 开始 -----------------------
    /**
     * <p>@Description 生产人员 接收数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/receive_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员接收数量", notes = "生产人员本月接收的总数量", httpMethod = "POST")
    public DggRestResponse receiveProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //操作人是自己的
            params.put("operaterId",userId);
            //操作类型: 接收 22
            params.put("operateTypeList",new String[]{"22"});
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productSystemCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 办理量统计(统计当月进入办理中的数量) </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/handle_inprocess_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员办理量统计", notes = "生产人员当月进入办理中的数量", httpMethod = "POST")
    public DggRestResponse handleInprocessProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //接收人是自己的
            params.put("receiverId",userId);
            params.put("currentMonth","yes");//不用管现在状态是否办理中,只管当月接收就行
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 生产完结量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_over_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员生产完结量", notes = "生产人员当月生产完结的数量", httpMethod = "POST")
    public DggRestResponse allOverProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人是自己的
            params.put("flowUserId",userId);
            //完结
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE});
            params.put("currentMonth","yes");//接收时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 已退订单量 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/complete_back_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员已退订单量", notes = "生产人员当月已退订单量", httpMethod = "POST")
    public DggRestResponse completeBackProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //接收人是自己的
            params.put("receiverId",userId);
            //已退单
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK});
            params.put("returnMonth","yes");//退单完成时间为当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description  生产人员 结项订单量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_junctions_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员结项订单量", notes = "生产人员当月结项的订单量", httpMethod = "POST")
    public DggRestResponse allJunctionsProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人是自己的
            params.put("flowUserId",userId);
            //结项
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_JUNCTIONS});
            params.put("currentMonth","yes");//接收时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 待接收数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_receive_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员待接收", notes = "生产人员所有在待接收状态的生产订单", httpMethod = "POST")
    public DggRestResponse waitReceiveProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //接收人或者负责人是自己的
            params.put("receiverOrProducterId",userId);
            //各种待接收
            params.put("statusList",new String[]{ScProductConstant.SC_TO_RECEIVE_FPDJS
                    ,ScProductConstant.SC_TO_RECEIVE_ZDDJS,ScProductConstant.SC_TO_RECEIVE_YJDJS,ScProductConstant.SC_TO_RECEIVE_TDDJS});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 所有办理中 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/inprocess_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员办理中", notes = "生产人员所有正在办理中的生产订单数量", httpMethod = "POST")
    public DggRestResponse inprocessProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //接收人是自己的
            params.put("flowUserId",userId);
            //办理中
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_IN_PROCESS});
            //params.put("currentMonth","yes");//这里是所有
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 生产暂停 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/suspend_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员生产暂停", notes = "生产人员所有在暂停中的生产订单数量", httpMethod = "POST")
    public DggRestResponse suspendProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人员是自己的
            params.put("flowUserId",userId);
            //生产订单状态为暂停
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_SUSPEND});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 退单审核中</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/charge_back_auditing_producter_count.do")
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员退单审核中", notes = "生产人员所有正在退单审核中的生产订单数量", httpMethod = "POST")
    public DggRestResponse chargeBackAuditingProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人员是自己的
            params.put("flowUserId",userId);
            //退单待审核
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_CHARGEBACK_DSH});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 退单驳回</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/charge_back_down_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员退单驳回", notes = "生产人员所有被退单驳回的生产订单数量", httpMethod = "POST")
    public DggRestResponse chargeBackDownProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人员是自己的
            params.put("flowUserId",userId);
            //退单驳回
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_CHARGEBACK_TDBH});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 接收超期</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 14:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/receive_over_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员接收超期", notes = "生产人员所有接收超期的数量", httpMethod = "POST")
    public DggRestResponse receiveOverProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //接收人或者负责人是自己的
            params.put("receiverOrProducterId",userId);
            //接收超期状态为超期
            params.put("receiveTimeStatus",ScProductConstant.TIME_OUT);
            params.put("notReceiveStatus","yes");
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 生产人员 办理超期量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/handle_over_producter_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "生产人员办理超期量", notes = "生产人员办理中的订单超期的数量", httpMethod = "POST")
    public DggRestResponse handleOverProducterCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            //流程人员是自己的
            params.put("flowUserId",userId);
            //查所有订单超期的数量
            params.put("orderTimeStatus",ScProductConstant.TIME_OUT);
            //不包含（已完结、已结项、已退单、待分配）
            params.put("notStatusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE
                    ,ScProductConstant.SC_ORDER_JUNCTIONS,ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK
                    ,ScProductConstant.SC_TO_RECEIVE_XDDJS,ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }



    //---------------  生产人员 工作台 结束 -----------------------

    //---------------  管理人员 工作台 22个 开始 -----------------------
    /**
     * <p>@Description 团队   (跟分单人员的一样全部的)待分配数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_allot_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员待分配数量", notes = "管理人员部门及以下待分配数量", httpMethod = "POST")
    public DggRestResponse waitAllotTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //查本事业部的
            Long userSybId = commonService.findUserSyb(userEntity);//查事业部ID
            params.put("signOrgId",userSybId);
            //待分配和退回待分配
            params.put("statusList",new String[]{ScProductConstant.SC_TO_RECEIVE_XDDJS,ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队待接收数量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/wait_receive_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员待接收数量", notes = "管理人员部门及以下待接收数量", httpMethod = "POST")
    public DggRestResponse waitReceiveTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("receiveOrProductOrgList",childOrganizationList);//流程人员的部门
            //各种待接收
            params.put("statusList",new String[]{ScProductConstant.SC_TO_RECEIVE_FPDJS
                    ,ScProductConstant.SC_TO_RECEIVE_ZDDJS,ScProductConstant.SC_TO_RECEIVE_YJDJS,ScProductConstant.SC_TO_RECEIVE_TDDJS});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }



    /**
     * <p>@Description 团队退单审核中</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/charge_back_auditing_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员退单审核中数量", notes = "管理人员部门及以下退单审核中数量", httpMethod = "POST")
    public DggRestResponse chargeBackAuditingTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            //params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            params.put("orgIdList", childOrganizationList);//获取本部门以及下属部门
            Map userMap = new HashMap(){{put("orgIds",childOrganizationList);put("locked",0);}};
            List<UserDTO> userDTOPage = userService.findUserDTOPage(userMap);//查部门下面所有人
            List<Long> userIds = new ArrayList<>();
            for (UserDTO userDTO : userDTOPage) {
                userIds.add(userDTO.getId());
            }
            params.put("userIds",userIds);
            //退单待审核
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_CHARGEBACK_DSH});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队退单驳回</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/charge_back_down_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员退单驳回", notes = "管理人员部门及以下退单驳回中的数量", httpMethod = "POST")
    public DggRestResponse chargeBackDownTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            //params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            params.put("orgIdList", childOrganizationList);//获取本部门以及下属部门
            Map userMap = new HashMap(){{put("orgIds",childOrganizationList);put("locked",0);}};
            List<UserDTO> userDTOPage = userService.findUserDTOPage(userMap);//查部门下面所有人
            List<Long> userIds = new ArrayList<>();
            for (UserDTO userDTO : userDTOPage) {
                userIds.add(userDTO.getId());
            }
            params.put("userIds",userIds);
            //退单驳回
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_CHARGEBACK_TDBH});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 团队办理量统计(统计当月进入办理中的数量) </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/handle_inprocess_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员办理量", notes = "管理人员部门及以下当月进入办理中的数量", httpMethod = "POST")
    public DggRestResponse handleInprocessTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            //当月接收的
            params.put("currentMonth","yes");
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队已退订单量 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/complete_back_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员已退订单量", notes = "管理人员本部门及以下当月已退订单的数量", httpMethod = "POST")
    public DggRestResponse completeBackTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            //已退单
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK});
            params.put("returnMonth","yes");//退单完成时间为当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 团队生产暂停 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/suspend_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员生产暂停", notes = "管理人员部门及以下全部状态为生产暂停的订单数量", httpMethod = "POST")
    public DggRestResponse suspendTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            //生产订单状态为暂停
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_SUSPEND});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 退单待审核 </p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/back_auditing_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员退单待审核", notes = "管理人员部门及以下所有正在退单待审核状态的订单数量", httpMethod = "POST")
    public DggRestResponse backAuditingTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员的部门
            //生产订单状态为退单待审核
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_CHARGEBACK_DSH});
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 团队分配总量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_allot_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员分配总量", notes = "管理人员部门及以下当月分配的总生产订单数量", httpMethod = "POST")
    public DggRestResponse allAllotTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);//操作人的部门
            //操作类型: 分配 17
            params.put("operateTypeList",new String[]{"17"});
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productSystemCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队接收总量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_receive_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员接收总量", notes = "管理人员部门及以下当月接收的生产订单总数量", httpMethod = "POST")
    public DggRestResponse allReceiveTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);//操作人的部门
            //操作类型: 接收 22
            params.put("operateTypeList",new String[]{"22"});
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productSystemCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队分配率</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/receive_team_rate.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员分配率", notes = "管理人员部门及以下的当月的分配总量除以接单量", httpMethod = "POST")
    public DggRestResponse receiveTeamRate() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);
            //操作类型: 分配 17
            params.put("operateTypeList",new String[]{"17"});
            params.put("currentMonth","yes");//统计当月
            Integer allotNum = apiProductionService.productSystemCount(params);
            //接单量 : 54 接单(既生成生产订单)
            params.put("operateTypeList",new String[]{"54"});
            Integer receiveNum = apiProductionService.productSystemCount(params);
            //分配率 = 分配总量/接单量
            if (receiveNum != 0){
                BigDecimal rate = new BigDecimal(allotNum).divide(new BigDecimal(receiveNum),BigDecimal.ROUND_HALF_UP,2)
                        .multiply(new BigDecimal(100));
                return this.getSuccessResponse(rate);
            }else {
                return this.getSuccessResponse(0);
            }

        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 团队接收率</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/allot_team_rate.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员接收率", notes = "管理人员部门及以下当月的接收量除以分配总量", httpMethod = "POST")
    public DggRestResponse allotTeamRate() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);//操作人的部门
            //操作类型: 分配 17
            params.put("operateTypeList",new String[]{"17"});
            params.put("currentMonth","yes");//统计当月
            Integer allotNum = apiProductionService.productSystemCount(params);
            //接单量 : 22 接收
            params.put("operateTypeList",new String[]{"22"});
            Integer receiveNum = apiProductionService.productSystemCount(params);
            //接收率=接收量/分配总量
            if (receiveNum != 0){
                BigDecimal rate = new BigDecimal(receiveNum).divide(new BigDecimal(allotNum),BigDecimal.ROUND_HALF_UP,2)
                        .multiply(new BigDecimal(100));
                return this.getSuccessResponse(rate);
            }else {
                return this.getSuccessResponse(0);
            }

        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队退单率</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/chargeback_team_rate.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员退单率", notes = "管理人员部门及以下当月的退单量除以接单量", httpMethod = "POST")
    public DggRestResponse chargebackTeamRate() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            //已退单
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK});
            params.put("returnMonth","yes");//退单完成时间为当月
            Integer backNumber = apiProductionService.productOrderCount(params);
            //接单量 : 54 接单(既生成生产订单)
            params.put("operateTypeList",new String[]{"54"});
            params.put("organizationList",childOrganizationList);//操作人部门
            params.put("statusList",null);//清空
            params.put("flowerUserOrganizationList",null);//清空
            Integer receiveNum = apiProductionService.productSystemCount(params);
            //退单率=退单量/接单量
            if (receiveNum != 0){
                BigDecimal rate = new BigDecimal(backNumber).divide(new BigDecimal(receiveNum),BigDecimal.ROUND_HALF_UP,2)
                        .multiply(new BigDecimal(100));
                return this.getSuccessResponse(rate);
            }else {
                return this.getSuccessResponse("0");
            }
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 团队节点超期率=节点超期量/办理量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/node_over_team_rate.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员节点超期率", notes = "管理人员部门及以下当月的节点超期量除以办理量", httpMethod = "POST")
    public DggRestResponse nodeOverTeamRate() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);//流程人员部门
            //节点状态为超期的
            params.put("nodeTimeStatus",ScProductConstant.TIME_OUT);
            params.put("currentMonth","yes");//统计当月
            Integer overNum = apiProductionService.productOperatingCount(params);
            //办理量条件
            Map<String,Object> inParams = new HashMap<>();
            inParams.put("currentMonth","yes");//接收时间为当月
            inParams.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            Integer handleNum = apiProductionService.productOrderCount(inParams);

            //节点超期率=节点超期量/办理量
            if (handleNum != 0){
                BigDecimal rate = new BigDecimal(overNum).divide(new BigDecimal(handleNum),BigDecimal.ROUND_HALF_UP,2)
                        .multiply(new BigDecimal(100));
                return this.getSuccessResponse(rate);
            }else {
                return this.getSuccessResponse(0);
            }

        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队 订单超期率=订单超期量/办理量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/8/21 0021 16:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/order_over_team_rate.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员订单超期率", notes = "管理人员部门及以下当月的订单超期量除以办理量", httpMethod = "POST")
    public DggRestResponse orderOverTeamRate() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            //当月超期量条件
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);//流程人员部门
            //查所有订单超期的数量
            params.put("orderTimeStatus",ScProductConstant.TIME_OUT);
            //接收时间为当月
            params.put("currentMonth","yes");
            Integer overNum = apiProductionService.productTimeStatusCount(params);
            //办理量条件
            Map<String,Object> inParams = new HashMap<>();
            inParams.put("currentMonth","yes");//接收时间为当月
            inParams.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            Integer handleNum = apiProductionService.productOrderCount(inParams);
            //订单超期率=订单超期量/办理量
            if (handleNum != 0){
                BigDecimal rate = new BigDecimal(overNum).divide(new BigDecimal(handleNum),BigDecimal.ROUND_HALF_UP,2)
                        .multiply(new BigDecimal(100));
                return this.getSuccessResponse(rate);
            }else {
                return this.getSuccessResponse(0);
            }
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 团队结项订单量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_junctions_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员结项订单量", notes = "管理人员部门及以下当月的结项订单数量", httpMethod = "POST")
    public DggRestResponse allJunctionsTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            //结项
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_JUNCTIONS});
            params.put("currentMonth","yes");//接收时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }
    /**
     * <p>@Description 团队生产完结量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/all_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员生产完结量", notes = "管理人员部门及以下当月生产完结数量", httpMethod = "POST")
    public DggRestResponse allOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            //完结
            params.put("statusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE});
            params.put("currentMonth","yes");//接收时间当月
            Integer integer = apiProductionService.productOrderCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 团队节点超期量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/node_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员节点超期量", notes = "管理人员部门及以下当月的节点超期的生产订单数量", httpMethod = "POST")
    public DggRestResponse nodeOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            //节点状态为超期的
            params.put("nodeTimeStatus",ScProductConstant.TIME_OUT);
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productOperatingCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队订单超期量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/order_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员订单超期量", notes = "管理人员部门及以下当月的订单超期的数量", httpMethod = "POST")
    public DggRestResponse orderOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("flowerUserOrganizationList",childOrganizationList);//流程人员部门
            //查所有订单超期的数量
            params.put("orderTimeStatus",ScProductConstant.TIME_OUT);
            params.put("currentMonth","yes");//统计当月
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }


    /**
     * <p>@Description 团队分配超期</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 14:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/allot_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员分配超期", notes = "管理人员部门及以下所有分配超期", httpMethod = "POST")
    public DggRestResponse allotOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //查本事业部的
            Long userSybId = commonService.findUserSyb(userEntity);//查事业部ID
            params.put("signOrgId",userSybId);
            //分配超期状态为超期
            params.put("distributionTimeOutStatus",ScProductConstant.TIME_OUT);
            params.put("notAllotStatus","yes");
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团接收超期</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 14:54 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/receive_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员接收超期", notes = "管理人员部门及以下接收超期", httpMethod = "POST")
    public DggRestResponse receiveOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            //获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("receiveOrProductOrgList",childOrganizationList);
            //接收状态为超期
            params.put("receiveTimeStatus",ScProductConstant.TIME_OUT);
            params.put("notReceiveStatus","yes");
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    /**
     * <p>@Description 团队办理超期量</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/6 0006 11:20 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "v1/handle_over_team_count.do", method = RequestMethod.POST)
    @ResponseBody
    @NLog()
    @ApiOperation(value = "管理人员办理超期", notes = "管理人员部门及以下所有办理超期的生产订单数量", httpMethod = "POST")
    public DggRestResponse handleOverTeamCount() {
        try {
            UserEntity currentUser = sessionManager.getCurrentUser();
            Long userId = currentUser.getId();
            Map<String,Object> params = new HashMap<>();
            UserEntity userEntity = userService.findUserById(userId);
            ////获取本部门及所有下属部门ID
            List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
            params.put("organizationList",childOrganizationList);
            //查所有订单超期的数量
            params.put("orderTimeStatus",ScProductConstant.TIME_OUT);
            //不包含（已完结、已结项、已退单、待分配）
            params.put("notStatusList",new String[]{ScProductConstant.SC_ORDER_OVER
                    ,ScProductConstant.SC_ORDER_OVER_OVERDUE,ScProductConstant.SC_ORDER_OVER_FORCE
                    ,ScProductConstant.SC_ORDER_JUNCTIONS,ScProductConstant.SC_ORDER_FINISHED_CHARGEBACK
                    ,ScProductConstant.SC_TO_RECEIVE_XDDJS,ScProductConstant.SC_ORDER_BACK_TO_ALLOT});
            Integer integer = apiProductionService.productTimeStatusCount(params);
            return this.getSuccessResponse(integer);
        }  catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse("0");
        }
    }

    //---------------  管理人员 工作台 结束 -----------------------


}
